<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="治疗人" prop="uName">
        <el-input
          v-model="queryParams.uName"
          placeholder="请输入治疗人名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="病历号" prop="blCode">
        <el-input
          v-model="queryParams.blCode"
          placeholder="请输入病历号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
   <!-- <el-form-item label="开始时间" prop="startTime">
        <el-date-picker clearable
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择治疗开始时间">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择治疗结束时间">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['kenuo:record:remove']"
        >删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['kenuo:record:export']"
        >导出</el-button>

      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="客户ID" align="center" prop="treatorId" /> -->
      <!-- <el-table-column label="病历号" align="center" prop="blCode" /> -->
      <el-table-column label="治疗人" align="center" prop="uname" />
      <el-table-column label="设备名称" align="center" prop="remarkOne" />
      <el-table-column label="设备SN码" align="center" prop="snCode" />
       <!-- <el-table-column label="治疗次数" align="center" prop="" /> -->
      <!-- <el-table-column label="治疗方案" align="center" prop="scheme"  width="150"> -->
      <!-- <template slot-scope="scope">
        <el-select v-model="scope.row.scheme" disabled placeholder="" multiple>
          <el-option  label="内激光照射" key="1" value="1"></el-option>
          <el-option  label="外激光照射" key="2" value="2"></el-option>
          <el-option  label="贝茨训练" key="3" value="3"></el-option>
           <el-option  label="多光谱训练" key="4" value="4"></el-option>
        </el-select>
        </template>
      </el-table-column>
      <el-table-column label="治疗时间" align="center" prop="treatTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.treatTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="治疗开始时间" align="center" prop="startTime" width="180">
      <!--  <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="治疗结束时间" align="center" prop="endTime" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>

            <el-table-column label="治疗时长" align="center" prop="remarkTwo" >
                      <template slot-scope="scope">
          <span>{{scope.row.remarkTwo}} 分钟</span>
        </template>
            </el-table-column>

                  <el-table-column label="联系方式" align="center" prop="tel" /> 
                                    <el-table-column label="方案类别" align="center" prop="ftype" /> 
                                                   <el-table-column label="治疗方案" align="center" prop="scheme" /> 
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >刪除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改统计对话框 -->
    <el-dialog  :title="title" :visible.sync="open" v-if="open" width="50%" append-to-body >
      <Statistics :selectedItem="selectedItem"></Statistics>
    </el-dialog>
  </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/kenuo/record";
import Statistics from './statistics.vue'
export default {
  name: "Record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        treatorId: null,
        treatName: null,
        scheme: null,
        treatTime: null,
        completion: null,
        snCode: null,
        uname:null,
        followUser: null,
        followUserTel: null,
        startTime: null,
        endTime: null,
        remarkOne: null,
        remarkTwo: null,
        remarkThree: null
      },
      // 表单参数
      form: {},
      // 表单校验
      selectedItem:{}
    };
  },
  components:{
    Statistics
  },
  created() {
    this.getList();
  },
  methods: {

    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
         this.recordList = response.rows.map(item=>{
           let obj = {...item}
           obj.scheme = item.scheme.split(",")
            console.log(obj)
           return obj
        })

        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        treatorId: null,
        treatName: null,
        scheme: null,
        treatTime: null,
        completion: null,
        snCode: null,
        followUser: null,
        followUserTel: null,
        startTime: null,
        endTime: null,
        remarkOne: null,
        remarkTwo: null,
        remarkThree: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // 统计
    handStatistics(row){
      this.selectedItem=row
      this.open = true;
      this.title = "统计";
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加治疗记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除这条数据项？').then(function() {
        return delRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('kenuo/record/export', {
        ...this.queryParams
      }, `record_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
